package cn.yfxu.server.service.impl;

import cn.yfxu.server.pojo.MenuRole;
import cn.yfxu.server.mapper.MenuRoleMapper;
import cn.yfxu.server.pojo.Result;
import cn.yfxu.server.service.IMenuRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yfxu
 * @since 2021-03-08
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {

    @Autowired
    private MenuRoleMapper menuRoleMapper;
    //更新角色菜单
    @Override
    @Transactional
    public Result updateMemuRole(Integer rid, Integer[] mids) {
         menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid",rid));
         if (null==mids||0==mids.length){
             return Result.success("更新成功!");
         }
        Integer result = menuRoleMapper.insertBatch(rid, mids);
         if (result==mids.length){
             return Result.success("更新成功");
         }
        return Result.error("更新失败");
    }
}
